<?php
$this->LoadHelper('ApiHelper');
$ApiHelper = new ApiHelper();

$this->LoadHelper('DealersHelper');
$DealersHelper = new DealersHelper();

$this->LoadHelper('MemberHelper');
$MemberHelper = new MemberHelper();

$this->LoadHelper('BranchHelper');
$BranchHelper = new BranchHelper();

$check = $ApiHelper->tokenCheck($this->Param);
if(!$check['success']) ErrorMsg::ApiMsg($check['msg'], $check['code']);

switch($this->Param['option']){
    case 'list':
        
        $member = $MemberHelper->getMemberRow($this->Param['uid']);
        
        $where = array(
            '`dl_status` = ?' => 'ok'
        );
        switch ($member['u_dp_type']){
            case 'dot':
                $where['`dl_brid` = ?'] = $member['u_dp_id'];
                break;
            case 'rg':
                $branch = $BranchHelper->branchAll(array('`br_rgid` = ?' => $member['u_dp_id'], '`br_status` = ?' => 'ok'));
                $branch_id = array(0);
                if(!empty($branch)) foreach($branch as $k => $v){
                    $branch_id[] = $v['br_id'];
                }
                $where['`dl_brid` IN (?)'] = $branch_id;
                break;
        }
        $data = $DealersHelper->dealersAll($where);
        $ApiHelper->logSave('getdealers', $this->Param);
        ErrorMsg::ApiMsg('请求成功', 0 , $data);
        break;
}